package com.ict.txmsv2.controller.system;

import com.ict.txmsv2.model.MethodDescrition;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.model.Role;
import com.ict.txmsv2.services.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linzzz
 * @desc ...
 * @date 2020-12-16
 */
@RestController
@RequestMapping("/system/roles")
public class SystemRolesController {
    @Autowired
    RoleService roleService;

    @MethodDescrition("获取所有角色")
    @GetMapping("/")
    public List<Role> getAllRole(){
        return roleService.getAllRole();
    }

    @MethodDescrition("添加角色")
    @PostMapping("/")
    public RespBean addRole(Role role){
        if (roleService.addRole(role)==1) {
            return RespBean.ok("添加成功");
        }
        return RespBean.error("失败咯");
    }

    @MethodDescrition("修改")
    @PutMapping("/")
    public RespBean updateRole(@RequestBody Role role){
        if (roleService.updateRole(role) == 1){
            return RespBean.ok("修改成功");
        }
        return RespBean.error("失败了");
    }

    @MethodDescrition("删除")
    @DeleteMapping("/{rid}")
    public RespBean deleteRole(@PathVariable Integer rid){
        if (roleService.delRole(rid) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("失败了");
    }
}
